package eu.epfc.dnet.mastermind.model.pojos;

import eu.epfc.dnet.mastermind.model.beans.Token;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Pierre Buvé
 */
public class GameDataModel {

    private int gameId;
    private int currentLine;
    private int duration;
    private Map<String, Object> gameData;
    private TokenColorList tokenColorList = new TokenColorList();
    private Line line01 = new Line();
    private Line line02 = new Line();
    private Line line03 = new Line();
    private Line line04 = new Line();
    private Line line05 = new Line();
    private Line line06 = new Line();
    private Line line07 = new Line();
    private Line line08 = new Line();
    private Line line09 = new Line();
    private Line line10 = new Line();
    private String status;
    private List<Token> solution = new ArrayList<Token>();

    public GameDataModel(int gameId, List<Token> solution) {
        System.out.println(this.getClass() + " Constructeur appelé avec paramètres : " + gameId + " , " + solution);
        
        //Création de la hashmap contenant les données du jeu
        gameData = new HashMap<String, Object>();

        // Stockage dans la map de la liste des token disponibles       
        gameData.put("alltokenslist", tokenColorList.getListColor());

        // Stockage dans la map des lignes
        gameData.put("line01", line01);
        gameData.put("line02", line02);
        gameData.put("line03", line03);
        gameData.put("line04", line04);
        gameData.put("line05", line05);
        gameData.put("line06", line06);
        gameData.put("line07", line07);
        gameData.put("line08", line08);
        gameData.put("line09", line09);
        gameData.put("line10", line10);

        // Initialisé la ligne courante à 1.
        currentLine = 1;
        gameData.put("currentline", currentLine);

        // récupère le gameId et le stocke dans la map
        this.gameId = gameId;
        gameData.put("gameid", gameId);

        // Récupère la solution et l'inscrit dans la map
        this.solution = solution;
        gameData.put("solution", solution);
        
        // set le status à NEW
        status = "NEW";
        gameData.put("status", status);
        
        // set la duration à 0
        duration = 0;
        gameData.put("duration", duration);
    }

    /**
     * Methode servant à mettre a jour le numéro de la ligne en cours.
     * @param line 
     */
    public void updateCurrentLine(Line line) {
        if (currentLine == 1) {
            line01 = line;
        } else if (currentLine == 2) {
            line02 = line;
        } else if (currentLine == 3) {
            line03 = line;
        } else if (currentLine == 4) {
            line04 = line;
        } else if (currentLine == 5) {
            line05 = line;
        } else if (currentLine == 6) {
            line06 = line;
        } else if (currentLine == 7) {
            line07 = line;
        } else if (currentLine == 8) {
            line08 = line;
        } else if (currentLine == 9) {
            line09 = line;
        } else if (currentLine == 10) {
            line10 = line;
        }
    }
    
    /**
     * Methode chargée de la mise à jour de la map
     */
    public void updateGameData() {
        gameData.put("currentline", currentLine);
        gameData.put("status", status);
        gameData.put("duration", duration);
        gameData.put("line01", line01);
        gameData.put("line02", line02);
        gameData.put("line03", line03);
        gameData.put("line04", line04);
        gameData.put("line05", line05);
        gameData.put("line06", line06);
        gameData.put("line07", line07);
        gameData.put("line08", line08);
        gameData.put("line09", line09);
        gameData.put("line10", line10);
    }
    
    /**
     * Renvoie la HashMap contenant les données de jeu.
     * @return 
     */
    public Map<String, Object> getGameData() {
        return gameData;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }
    

    public int getCurrentLine() {
        return currentLine;
    }

    public void setCurrentLine(int currentLine) {
        this.currentLine = currentLine;
    }

    public Line getLine01() {
        return line01;
    }

    public void setLine01(Line line01) {
        this.line01 = line01;
    }

    public Line getLine02() {
        return line02;
    }

    public void setLine02(Line line02) {
        this.line02 = line02;
    }

    public Line getLine03() {
        return line03;
    }

    public void setLine03(Line line03) {
        this.line03 = line03;
    }

    public Line getLine04() {
        return line04;
    }

    public void setLine04(Line line04) {
        this.line04 = line04;
    }

    public Line getLine05() {
        return line05;
    }

    public void setLine05(Line line05) {
        this.line05 = line05;
    }

    public Line getLine06() {
        return line06;
    }

    public void setLine06(Line line06) {
        this.line06 = line06;
    }

    public Line getLine07() {
        return line07;
    }

    public void setLine07(Line line07) {
        this.line07 = line07;
    }

    public Line getLine08() {
        return line08;
    }

    public void setLine08(Line line08) {
        this.line08 = line08;
    }

    public Line getLine09() {
        return line09;
    }

    public void setLine09(Line line09) {
        this.line09 = line09;
    }

    public Line getLine10() {
        return line10;
    }

    public void setLine10(Line line10) {
        this.line10 = line10;
    }

    public List<Token> getSolution() {
        return solution;
    }

    public int getGameId() {
        return gameId;
    }
    
    
}
